home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15493 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.8 KB  |  95 lines

  1. Path: global.gc.net!sourcebbs!david.mohorn
  2. From: david.mohorn@sourcebbs.com (DAVID MOHORN)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: COLLEGE PROFESSORS! #
  5. Message-ID: <8BEE4D1.02C700325C.uuout@sourcebbs.com>
  6. Date: Thu, 18 Apr 96 20:33:00 -0500
  7. Distribution: world
  8. Organization: SelectiveSourceBBS VirginiaBeach  (804)471 6776
  9. Reply-To: david.mohorn@sourcebbs.com (DAVID MOHORN)
  10. References: <Pine.A32.3.91.960417134130.26474G-100000@red.weeg.uiowa.edu
  11. X-Newsreader: PCBoard Version 15.22
  12. X-Mailer: PCBoard/UUOUT Version 1.20
  13.  
  14. RN>> The instructors philosophy is to make it more "readable" and keep it as
  15.   >> structured as possible!  As if structured programming was the only way
  16.   >> to accomplish this task.  He also stated that nested ifs make the code
  17.   >> harder to read. He also stated that there is no arm in wasting a
  18.   >> few milliseconds doing the extra conditions, since it won't be
  19.   >> noticeable anyway.
  20.  
  21. RN> This is a perfectly valid approach, and a common one.  I daresay that
  22.   >he's doubly smart for insisting on a structured programming approach in a
  23.   >language that has traditionally encouraged spaghetti code.
  24.   >There _is_ no harm is wasting a few microseconds, if it makes the code
  25.   >clearer (which avoids wasting a few days, or weeks, or months spent
  26.   >debugging or maintaining or even trying to comprehend the code).  And if the
  27.   >compiler's smart enough, it might produce efficient code for the
  28.   >professor's approach.  I share my Prolog professor's confusion over
  29.   >people being in such a hurry to get the wrong answer.
  30.  
  31. I agree.  There are times when writing such code that readability is
  32. more important than efficiency, but the logic of this code was
  33. illogical, verified data that was already identified as being invalid,
  34. so why continue scanning the data...  I think a construct such as:
  35.  
  36. if(whatever) abort=1
  37. else process_data
  38.  
  39. if(whatever) abort=1
  40. else process_data
  41.  
  42. if(whatever) abort=1
  43. else process_data
  44.  
  45. if(abort==1) return ERROR
  46.  
  47. is more confusing than a simple:
  48.  
  49. if(whatever) return ERROR
  50. else process_data
  51.  
  52. if(whatever) return ERROR
  53. else process_data
  54.  
  55. if(whatever) return ERROR
  56. else process_data
  57.  
  58. The former example still checked the last two ifs, even if the first if
  59. set the variable abort to the value 1.  The last latter example,
  60. however, is much faster and easier to read.
  61.  
  62. RN>> I retorted his remark and said it would on a multitasking system where
  63.   >> every cycle counts!  If I were validating 10,000 data items, example 1
  64.   >> would take a considerable amount of time longer than example 2!
  65.  
  66. RN>  In this day and age of Alphas, Pentiums, PowerPCs, MIPSs, and home
  67.   >computers with 24MB of interleaved DIMM RAM, which multitasking systems are
  68.   >those?  Do you honestly believe that Windows code squeezes out every
  69.   >microsecond?  Besides, if you were so concerned about speed, you'd be
  70.   >writing in assembly, FORTRAN or C and making calls to the API at the
  71.   >lowest possible level.  And you'd _still_ be writing structured code, if you
  72.   >ever wanted to make sense of your program again.
  73.   >  Dev platforms like Delphi, Forte and VB allow the programmer to work at a
  74.   >very high level.  It is _assumed_ that clarity and rapid
  75.   >application development are the top priorities at that level.
  76.  
  77. VisualBASIC isn't all that bad...  And this type of mentality is why we
  78. have bloated, inefficient code today.  I have excellent games for my
  79. TRS-80 Model IV that fits on a 360K diskette--monochrome graphics and
  80. sound...  Now you buy games that are 2 CD-ROMS!
  81.  
  82. RN>> Does anyone else have any opinions or horror stories?
  83.  
  84. RN>  My horror story is one word long:  BASIC.
  85.  
  86. I disagree.
  87. ---
  88.  * QMPro 1.53 * main(int c){void *f[10];c=0;while(f)f[c++]=tmpfile();}
  89.  
  90.  
  91. ---
  92. This message originated from:  ----------        Selective Source BBS
  93.                                     -------    Virginia Beach, Virginia
  94.                                          -----      (804) 471 6776
  95.